import { fileURLToPath, URL } from "node:url";
import legacy from "@vitejs/plugin-legacy";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueDevTools from "vite-plugin-vue-devtools";
import basicSsl from "@vitejs/plugin-basic-ssl";
// NODE_ENV;
// https://vite.dev/config/
export default defineConfig({
  base: "./",
  plugins: [
    vue(),
    // vueDevTools(),
    legacy(),
    basicSsl()
  ],
  server: {
    host: "0.0.0.0", // 监听所有可用的网络接口
    open: true, // 是否自动在浏览器打开
    https: false,
    port: 5173, // 端口号
    //这里的ip和端口是前端项目的;下面为需要跨域访问后端项目
    proxy: {
      "/energy-device/": {
        // target: "http://192.168.1.103:9802",
        target: "https://device.ferryman.cc:88",
        // target: "http://10.200.199.16",
        changeOrigin: true,
        // secure: false, //是否https接口
        // rewrite: (path) => path.replace(/^\/api/, '') // 可选，重写路径
        rewrite: path => path.replace(/^\/energy-device/, "/energy-device")
      }
    },
    sourcemap: false,
    terserOptions: {
      // 生产环境移除console
      compress: {
        drop_console: false,
        drop_debugger: true
      }
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "./src/style/index.scss";`
      }
    }
  },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url))
    }
  }
});
